<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

use DB;

class CommentController extends Controller
{
    //评论首页
    public function index(Request $request)
    {
// 
        $where['name'] = $request->input('name');
        $db = DB::table('storecomment');

     
        $list = $db
            ->join('goods', 'storecomment.commentGid', '=', 'goods.id')
            ->join('storeuser', 'storecomment.commentUid', '=', 'storeuser.userId')
            // ->join('goodscate', 'goods.cid', '=', 'goodscate.id')
            ->select('.storecomment.commentStar','storecomment.commentPubTime','storecomment.commentBody','storeuser.userName','goods.name','storecomment.commentId','storecomment.commentStatu')
            ->where('goods.name','like',"%{$request->input('name')}%")
            // ->distinct()
            ->paginate(5);
            // ->get();
           

            //获取商品顶级分类
        	/*for ( $i = 0 ; $i< count($list); $i++ ) {
        		$id = $list[$i]->cid;
        		$top = DB::table('goodscate')->where('id',$id)->value('name');
        		$list[$i]->top = $top;

        	}*/
          // dd($list);
        	// var_dump($request->input('brand'));
            return view('admin.comments.comment',['list' => $list,'where' => $where] );
    
    }

    //删除评论
    public function destroy($id){
        
        DB::table('storecomment')->where('commentId',$id)->delete();

        $row = DB::table('stroereplay')->where('replayCid',$id)->first();
     
       if( $row ){

             $dow = DB::table('stroereplay')->where('replayCid',$id)->delete();
             return back()->with('msg','删除成功');
        
        }
        
             return back()->with('msg','删除成功');
    }
}
